﻿using Blazored.LocalStorage;
using Compass.Wasm.Client.Services.Categories;
using Compass.Wasm.Client.Services.Identities;
using Compass.Wasm.Client.Services.Logistics;
using Compass.Wasm.Client.Services.Plans;
using Compass.Wasm.Client.Services.Projects;
using Compass.Wasm.Client.Services.Purchases;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;

namespace Compass.Wasm.Client;

public static class Register
{
    public static WebAssemblyHostBuilder RegisterAppServices(this WebAssemblyHostBuilder builder)
    {
        builder.RootComponents.Add<App>("#app");
        builder.RootComponents.Add<HeadOutlet>("head::after");

        builder.Services.AddBootstrapBlazor();//注册 BootstrapBlazor 服务
        builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
        builder.Services.AddBlazoredLocalStorage();//浏览器LocalStorage，用于存储和读取token
        //Blazor授权
        builder.Services.AddScoped<AuthenticationStateProvider, AuthStateProvider>();
        builder.Services.AddAuthorizationCore();
        builder.Services.AddScoped<IUserService, UserService>();
        return builder;
    }
    public static WebAssemblyHostBuilder RegisterCategoryServices(this WebAssemblyHostBuilder builder)
    {
        #region Categories
        builder.Services.AddScoped<IProductService, ProductService>();
        builder.Services.AddScoped<IModelService, ModelService>();
        builder.Services.AddScoped<IModelTypeService, ModelTypeService>();

        #endregion
        return builder;
    }
    public static WebAssemblyHostBuilder RegisterProjectServices(this WebAssemblyHostBuilder builder)
    {
        #region Projects
        builder.Services.AddScoped<IProjectService, ProjectService>();
        builder.Services.AddScoped<IDrawingService, DrawingService>();
        builder.Services.AddScoped<ILessonService, LessonService>();


        #endregion
        return builder;
    }
    public static WebAssemblyHostBuilder RegisterPlanServices(this WebAssemblyHostBuilder builder)
    {
        #region Plans
        builder.Services.AddScoped<IMainPlanService, MainPlanService>();
        builder.Services.AddScoped<IIssueService, IssueService>();
        builder.Services.AddScoped<IPackingListService, PackingListService>();
        builder.Services.AddScoped<IPalletService, PalletService>();
        builder.Services.AddScoped<IFinishGoodsCountService, FinishGoodsCountService>();
        #endregion
        return builder;
    }
    public static WebAssemblyHostBuilder RegisterLogisticServices(this WebAssemblyHostBuilder builder)
    {
        builder.Services.AddScoped<IImportExportInfoService, ImportExportInfoService>();
        return builder;
    }
    public static WebAssemblyHostBuilder RegisterPurchaseServices(this WebAssemblyHostBuilder builder)
    {
        builder.Services.AddScoped<INavInvReportClassService, NavInvReportClassService>();
        builder.Services.AddScoped<INavInvValuationService, NavInvValuationService>();
        return builder;
    }
}